package com.wang.tool.common.result;

import com.wang.tool.common.ErrorInfo;
import com.wang.tool.common.SimpleException;

/**
 * 一般结果
 * @author shaopeng
 * @date 2023/5/23
 */
public class SimpleResult<T> extends BaseResult {
    private static final long serialVersionUID = -7564202278110846961L;


    /**
     * 结果
     */
    private T data;


    public static <T> SimpleResult<T> success() {
        return success(null, SUCCESS);
    }


    public static <T> SimpleResult<T> success(T data) {
        return success(data, SUCCESS);
    }

    public static <T> SimpleResult<T> success(T data, String status) {
        return build(true, data, status, null);
    }


    public static <T> SimpleResult<T> error() {
        SimpleResult<T> result = new SimpleResult<>();
        result.fillError(SimpleException.UNKNOWN_ERROR, SimpleException.UNKNOWN_ERROR);
        return result;
    }

    public static <T> SimpleResult<T> error(Throwable error) {
        SimpleResult<T> result = new SimpleResult<>();
        result.fillError(error);
        return result;
    }


    public static <T> SimpleResult<T> error(ErrorInfo error) {
        SimpleResult<T> result = new SimpleResult<>();
        result.fillError(error);
        return result;
    }

    public static <T> SimpleResult<T> error(String errorCode, String errorMsg) {
        SimpleResult<T> result = new SimpleResult<>();
        result.fillError(errorCode,errorMsg);
        return result;
    }


    public static <T> SimpleResult<T> build(boolean success, T data, String status, String message) {
        SimpleResult<T> result = new SimpleResult<>();
        result.setSuccess(success);
        result.setStatus(status);
        result.setData(data);
        result.setMessage(message);
        return result;
    }



    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
